package com.mshop.admin;

import java.util.List;

import com.mshop.fw.modules.SM;
import com.mshop.po.Manager;
import com.mshop.util.CONSTANTS;
import com.mshop.util.WebContext;

/**
 * 
 * 
 * Title:
 * 
 * Description:
 * 
 * Copyright: Copyright (c) 2008
 * 
 * @author haoxz11
 * @created Oct 21, 2008 11:16:42 AM
 * @version $Id: ManagerAction.java,v 1.1 2010/04/09 03:27:08 airsou Exp $
 */
public class ManagerAction extends WebAction {
	private String method;
	private String id;
	private Manager manager;

	public Manager getManager() {
		return manager;
	}

	public void setManager(Manager manager) {
		this.manager = manager;
	}

	/**
	 * Comment for <code>serialVersionUID</code>
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public String webProcess(WebContext context, Manager manager) {
		if ("add".equals(method)) {
			return "edit";
		} else if ("editme".equals(method)) {
			context.put("man", manager);
			return "editme";
		}else if ("edit".equals(method)) {
			Manager man = SM.ManagerService.get(
					id);
			context.put("man", man);
			return "edit";
		} else if ("delete".equals(method)) {
			if(SM.ManagerService.get(id)!=null){
				SM.ManagerService.delete(id);
				context.put("rmsg", CONSTANTS.TEXT.DELETE_SUCCESS_EN);
			}
			return "delete";
		} else if ("save".equals(method)) {
			SM.ManagerService.save(this.manager);
			context.put("rmsg", CONSTANTS.TEXT.SAVE_SUCCESS_EN);
			return "save";
		}else if ("saveme".equals(method)) {
			SM.ManagerService.save(this.manager);
			manager=this.manager;
			context.put("rmsg", CONSTANTS.TEXT.SAVE_SUCCESS_EN);
			return "saveme";
		} else if ("list".equals(method)) {
			List<Manager> managerList = SM.ManagerService.list();
			context.put("managerList", managerList);
			return "list";
		} else {
			method = "list";
			return this.webProcess(context, manager);
		}
	}

	public String getMethod() {
		return method;
	}

	public void setMethod(String method) {
		this.method = method;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	/* (non-Javadoc)
	 * @see com.camel.admin.WebAction#getSysLog()
	 */
	@Override
	public String getSysLog() {
		String opr="";
		if("add".equals(method)){
			opr=CONSTANTS.SYSLOG_TEXT.MANAGER.ADD;
		}else if("edit".equals(method)){
			opr=CONSTANTS.SYSLOG_TEXT.MANAGER.EDIT;
		}else if("delete".equals(method)){
			opr=CONSTANTS.SYSLOG_TEXT.MANAGER.DELETE;
		}else if("save".equals(method)){
			if(this.isEmptyId(manager)){
				opr=CONSTANTS.SYSLOG_TEXT.MANAGER.ADD_SAVE;
			}else{
				opr=CONSTANTS.SYSLOG_TEXT.MANAGER.EDIT_SAVE;
			}
		}else if("editme".equals(method)){
			opr=CONSTANTS.SYSLOG_TEXT.MANAGER.EDIT_ME;
		}else if("saveme".equals(method)){
			opr=CONSTANTS.SYSLOG_TEXT.MANAGER.EDIT_ME_SAVE;
		}else if("list".equals(method)){
			opr=CONSTANTS.SYSLOG_TEXT.MANAGER.LIST;
		}else{
			opr=CONSTANTS.SYSLOG_TEXT.MANAGER.LIST;
		}
		return opr;
	}
}
